<?php
	session_start();
	include('../config.php'); 
	if(!isset($_SESSION['ID']))
	{
		header("Location: ../login/index.php");
	}
	else
	{
	}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<link href="../style.css" rel="stylesheet" type="text/css" />
<style type="text/css">
body {
	background-image: url(images/topline.png) no-repeat;
	margin-left: 0px;
	margin-right: 0px;
}
</style>
</head>

<body>

<div class="container1">
  <div class="content">
	<div class="seclogo">
      <p><img src="../images/Logo TPN-02.png" alt="TPN" width="212" height="61" align="left" style="padding-left: 8px"/></p>
      <p>&nbsp;</p>
      <p>&nbsp;</p>
      <p><span class="Header">Research &amp; Planning</span></p></div>
      <div>
    <a href="../upload/index.php"><button class="button white">Upload Data</button></a>
    </div>
     <!-- end .content --></div>
  <!-- end .container --></div>
<div class="container2">
  <div class="content">
  <span class="subheader" align="left">Data set : <?php echo str_replace ($_SESSION['ID'], "", $_GET["filename"]);?></span>
  <button class="button selectall white" onclick="javascript:location.href='../sheetlist/index.php?filename=<?php echo $_GET["filename"]."&Page=".$_GET['Page'];?>'">Back</button>
  </div>
</div>

<div class="datatable">
    <p class="title"><?php echo $_GET["sheet"]; ?></p>
    <p class="subtitle">WEIGHTED</p>
    <p class="subtext">Proportions/Means: Columns Tested (5%, 10% risk level) - A/B - C/D/E/F - G/H/I/J - K/L/M - N/O - P/Q - R/S/T - U/V/W - X/Y<br />
    Overlap formulae used.</p>
    </div>
<div style="float: left; margin-left:10px; margin-right:2px">
<table border="1" cellpadding="3" cellspacing="0" style="width: 175px; padding-left:10px;"> 
    <tr>
    <td class="leftheader" height="34px" align="left" valign="middle" style="color:white; padding:3px 3px 3px 3px;"></td>
    </tr>
    <?php
  	LinkDataBase();
	$sql = "select * from ".$_GET["filename"]." where table_name = '".$_GET["sheet"]."'";
	$result= mysql_query($sql);
	
	while($row = mysql_fetch_assoc($result))
	{
		if($row['item'] != "")
		{
			echo '<tr>';
			echo '<td class="leftheader" height="34px" align="left" valign="middle" style="padding:3px 3px 3px 3px; border: solid 1px; border-color: #FFFFFF;">'.$row['item'].'</td>';
			echo '</tr>';
		}
		else
		{
			echo '<tr>';
			echo '<td class="leftheader" height="34px" align="left" valign="middle" style="color:white; padding:3px 3px 3px 3px; border: solid 1px; border-color: #FFFFFF;"></td>';
			echo '</tr>';
		}
	}
  	?>
    </table>
</div>

<div style="
    overflow: scroll;
    border-color: #dcdbda;
"> 
<table width="1729" border="1" cellpadding="3" cellspacing="0">
  <tr>
    <th class="tableheader" height="34" align="center" valign="middle">Total</th>
    <th class="tableheader" height="34" colspan="2" align="center" valign="middle">Gender</th>
    <th class="tableheader" height="34" colspan="4" align="center" valign="middle">Age</th>
    <th class="tableheader" height="34" colspan="4" align="center" valign="middle">Regions</th>
    <th class="tableheader" height="34" colspan="3" align="center" valign="middle">Income</th>
    <th class="tableheader" height="34" colspan="2" align="center" valign="middle">Marital Status</th>
    <th class="tableheader" height="34" colspan="2" align="center" valign="middle">Kids in HH</th>
    <th class="tableheader" height="34" colspan="3" align="center" valign="middle">Age of Children</th>
    <th class="tableheader" height="34" colspan="3" align="center" valign="middle">Race</th>
    <th class="tableheader" height="34" colspan="2" align="center" valign="middle">Ethnicity</th>
  </tr>
  <tr>
    <td class="tablecell-odd" height="34" align="center" valign="middle"></td>
    <td class="tablecell-odd" height="34" align="center" valign="middle">M</td>
    <td class="tablecell-odd" height="34" align="center" valign="middle">F</td>
    <td class="tablecell-odd" height="34" align="center" valign="middle">21-31</td>
    <td class="tablecell-odd" height="34" align="center" valign="middle">32-47</td>
    <td class="tablecell-odd" height="34" align="center" valign="middle">48-66</td>
    <td class="tablecell-odd" height="34" align="center" valign="middle">67+</td>
    <td class="tablecell-odd" height="34" align="center" valign="middle">NE</td>
    <td class="tablecell-odd" height="34" align="center" valign="middle">MW</td>
    <td class="tablecell-odd" height="34" align="center" valign="middle">S</td>
    <td class="tablecell-odd" height="34" align="center" valign="middle">W</td>
    <td class="tablecell-odd" height="34" align="center" valign="middle">&lt;50</td>
    <td class="tablecell-odd" height="34" align="center" valign="middle">50-100</td>
    <td class="tablecell-odd" height="34" align="center" valign="middle">100+</td>
    <td class="tablecell-odd" height="34" align="center" valign="middle">M</td>
    <td class="tablecell-odd" height="34" align="center" valign="middle">S</td>
    <td class="tablecell-odd" height="34" align="center" valign="middle">YES</td>
    <td class="tablecell-odd" height="34" align="center" valign="middle">NO</td>
    <td class="tablecell-odd" height="34" align="center" valign="middle">&lt;5</td>
    <td class="tablecell-odd" height="34" align="center" valign="middle">6-12</td>
    <td class="tablecell-odd" height="34" align="center" valign="middle">13-18</td>
    <td class="tablecell-odd" height="34" align="center" valign="middle">W</td>
    <td class="tablecell-odd" height="34" align="center" valign="middle">AA</td>
    <td class="tablecell-odd" height="34" align="center" valign="middle">A</td>
    <td class="tablecell-odd" height="34" align="center" valign="middle">H</td>
    <td class="tablecell-odd" height="34" align="center" valign="middle">NH</td>
  </tr>
  <?php
  	LinkDataBase();
	$sql = "select * from ".$_GET["filename"]." where table_name = '".$_GET["sheet"]."'";
	$result= mysql_query($sql);
	
	$RowCounter = 0;
	while($row = mysql_fetch_assoc($result))
	{
		if($RowCounter==0)
		{
		}
		else
		{
			echo "<tr>";
			$ColCounter=0;		
			foreach ($row as $cell) 
			{			
				if($ColCounter==27)
				{
					break;
				}
				else if($ColCounter==0)
				{
					$ColCounter++;
				}
				else
				{
					if($RowCounter%2 == 0)
					{
						echo '<td class="tablecell-odd" height="34" align="center" valign="middle">';
					}
					else
					{
						echo '<td class="tablecell" height="34" align="center" valign="middle">';
					}
					echo $cell;
					echo '</td>';
					$ColCounter++;
				}
			}
			echo "</tr>";
		}
		$RowCounter++;
	}
  ?>
</table>
</div>

    <div class="caption"><strong>Martial Status:</strong> M - Married/Partner, S = Not Married/Partner, <strong>Race:</strong> W - White, AA - African American, A - Asian, <strong>Ethnicity:</strong> H - Hispanic, NH - Not Hispanic</div>
  
<div class="container2">
  <div class="content">
  <button class="button backtotop white" onclick="javascript:location.href='../sheetlist/index.php?filename=<?php echo $_GET["filename"]."&Page=".$_GET['Page'];?>'">Back</button>
  <button class="button downloadcsv white" onclick="window.location='./csv.php?filename=<?php echo $_GET['filename']."&sheet=".str_replace("'","\'",$_GET["sheet"]);?>'">Download as csv</button>
  </div>
</div>
</body>
</html>
